﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace Sample.RegularExpression
{
    class RegularExpression
    {
        public static void Execute()
        {
            string prefix = "";
            Regex r = new Regex("((A(b)))");
            MatchCollection mc = r.Matches("XYZAbcAbcAbcXYZAbcAb");
            Console.WriteLine(String.Format("Number of matches found = {0}", mc.Count.ToString()));
            foreach(Match aMatch in mc)
            {
                prefix = "\t";
                Console.Write(prefix);
                Console.WriteLine(String.Format("Value of match: {0}, Index of match: {1}", aMatch.Value, aMatch.Index));
                GroupCollection gc = aMatch.Groups;
                Console.Write(prefix);
                Console.WriteLine(String.Format("Number of groups found = {0}", gc.Count));
                foreach (Group aGroup in gc)
                {
                    prefix = "\t\t";
                    Console.Write(prefix);
                    Console.WriteLine(String.Format("Value of group: {0}, Index of group: {1}", aGroup.Value, aGroup.Index));
                    CaptureCollection cc = aGroup.Captures;
                    Console.Write(prefix);
                    Console.WriteLine(String.Format("Number of captures found = {0}", cc.Count));
                    foreach (Capture aCapture in cc)
                    {
                        prefix = "\t\t\t";
                        Console.Write(prefix);
                        Console.WriteLine(String.Format("Value of capture: {0}, Index of capture: {1}", aCapture.Value, aCapture.Index));
                    }
                }
            }
        }
    }
}
